package sg.edu.nus.iss.cats.form;

import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.util.*;

public class UserForm extends ActionForm {

    private String userId;
    private String name;
    private String password;
    private String employeeId;
    private String[] roleIds;

    public void setUserId (String userId) {
        this.userId = userId;
    }

    public String getUserId (){
        return userId;
    }

    public void setName (String name) {
        this.name = name;
    }

    public String getName (){
        return name;
    }

    public void setPassword (String password) {
        this.password = password;
    }

    public String getPassword (){
        return password;
    }

    public void setEmployeeId (String employeeId) {
        this.employeeId = employeeId;
    }

    public String getEmployeeId () {
        return employeeId;
    }

    public void setRoleIds (String[] roleIds) {
        this.roleIds = roleIds;
    }

    public String[] getRoleIds () {
        
        return roleIds;
    }
    
  
 
	public ActionErrors validate (ActionMapping mapping, HttpServletRequest request) {

        //String s = null;
        ActionErrors errors = new ActionErrors ();
        MessageResources res = (MessageResources) request.getAttribute (Action.MESSAGES_KEY);

        // userId is mandatory
        validateMandatory (getUserId(), "fieldLabel.userId", res, errors);

        // password is mandatory
        validateMandatory (getPassword(), "fieldLabel.password", res, errors);

        return errors;
    }

    public void validateMandatory (String s, String labelKey,
                                    MessageResources res, ActionErrors errors) {
        if ((s == null) || (s.length() == 0)) {
            String fieldLabel = res.getMessage (labelKey);
            ActionError error = new ActionError ("error.fieldRequired", fieldLabel);
            errors.add (labelKey, error);
        }
    }

}